﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using CRM.Extensions;
using CRM.Interface;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;

namespace CRM.Models.SocialMarketing
{
    [Index(nameof(UserId))]
    [Index(nameof(CompanyId))]
    [Index(nameof(GroupId))]
    [Index(nameof(OemId))]
    public class SocialMarketingTask :BaseModel, ISoftDelete
    {
        public int Id { get; set; }
        
        public string Name { get; set; }
        public string Content { get; set; }

        [JsonIgnore]
        public string ImagesStr { get; set; } //= "";
        [NotMapped]
        public List<string> Images { get => ImagesStr.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList(); //ImagesStr?
            set => ImagesStr = string.Join(',', value);
        }
        
        public int ClickCount { get; set; }
        public int ReplyCount { get; set; }
        public int ShareCount { get; set; }
        public int LikeCount { get; set; }

        public DateTime PublishedAt { get; set; }
        
        [Column(TypeName = "tinyint")]
        public PublishState State { get; set; }
        
        [NotMapped]
        public string StateText => State.GetDescription();

        public enum PublishState
        {
            [Description("未发布")] 
            Unpublished,
            [Description("发布中")]
            Publishing,
            [Description("已发布")]
            Published,
            [Description("发布失败")]
            Error
        }

        public bool IsDeleted { get; set; }
        
        public int OemId { get; set; }
        public int GroupId { get; set; }
        public int CompanyId { get; set; }
        public int UserId { get; set; }
        public VkPost VkPost { get; set; }


    }
    
    [Owned]
    public class VkPost
    {
        public int Id { get; set; }
        public int ClickCount { get; set; }
        public int ReplyCount { get; set; }
        public int ShareCount { get; set; }
        public int LikeCount { get; set; }
    }
}